/* weatherInHouseMib.c - IDB+ Module source for weatherInHouseMib.mi2. */

/* Copyright 2013 Wind River, Inc. */
/*
modification history
--------------------
xxx,22Mar13,idb Created by IDBGEN. Ver 2.28
%%BeginUserCode weatherInHouseMib_Modifications
%%EndUserCode   weatherInHouseMib_Modifications
*/

/*
DESCRIPTION
This module defines the IDB+ structures and IDB+ Object handler routines to
access the IDB+ objects defined in weatherInHouseMib.mi2.

INCLUDE FILES: weatherInHouseMib.h
*/

/* Includes */
#include "neos_vx_win.h"
#include "jialianMib_function.h"
#include "idbLib.h"
#include "weatherInHouseMib.h"

/* %%BeginUserCode weatherInHouseMib_IncludeFiles */
/* %%EndUserCode   weatherInHouseMib_IncludeFiles */

/* Defines */
/* %%BeginUserCode weatherInHouseMib_Defines */
/* %%EndUserCode   weatherInHouseMib_Defines */

/* Globals */
/* %%BeginUserCode weatherInHouseMib_Globals */
/* %%EndUserCode   weatherInHouseMib_Globals */

/* Locals */
LOCAL char * moduleName = "weatherInHouseMib";
/* %%BeginUserCode weatherInHouseMib_Locals */
/* %%EndUserCode   weatherInHouseMib_Locals */

/* Prototypes */
LOCAL STATUS weatherInHouseMibScalarHandler ( idbRequest_t request, idb_t * idb );

/* %%BeginUserCode weatherInHouseMib_Prototypes */
/* %%EndUserCode   weatherInHouseMib_Prototypes */


/****************************************************************************
* IDB+ Module Object Descriptors
*/

LOCAL idbObjDesc_t temperature_objDesc[] = {
  { temperature, 1, 4, /* localId=0  1.3.6.1.4.1.123456.1.2.1 */
    { -20, 60 }, IDB_INTEGER, IDB_READ,
    (IDB_VALID), weatherInHouseMibScalarHandler,
    (char *)0, "weatherInHouseMib:temperature" },
  { 0 }
};

LOCAL idbObjDesc_t humidity_objDesc[] = {
  { humidity, 2, 4, /* localId=1  1.3.6.1.4.1.123456.1.2.2 */
    { 0, 0 }, IDB_Unsigned32, IDB_READ,
    (IDB_VALID), weatherInHouseMibScalarHandler,
    (char *)0, "weatherInHouseMib:humidity" },
  { 0 }
};

LOCAL idbObjDesc_t co2_objDesc[] = {
  { co2, 3, 4, /* localId=2  1.3.6.1.4.1.123456.1.2.3 */
    { 0, 0 }, IDB_Unsigned32, IDB_READ,
    (IDB_VALID), weatherInHouseMibScalarHandler,
    (char *)0, "weatherInHouseMib:co2" },
  { 0 }
};

LOCAL idbObjDesc_t airQuality_objDesc[] = {
  { airQuality, 4, 4, /* localId=3  1.3.6.1.4.1.123456.1.2.4 */
    { 0, 0 }, IDB_Unsigned32, IDB_READ,
    (IDB_VALID), weatherInHouseMibScalarHandler,
    (char *)0, "weatherInHouseMib:airQuality" },
  { 0 }
};

LOCAL idbObjDesc_t brightness_objDesc[] = {
  { brightness, 5, 4, /* localId=4  1.3.6.1.4.1.123456.1.2.5 */
    { 0, 0 }, IDB_Unsigned32, IDB_READ,
    (IDB_VALID), weatherInHouseMibScalarHandler,
    (char *)0, "weatherInHouseMib:brightness" },
  { 0 }
};

/*****************************************************************************
* IDB+ Module OID Table
*
* The OID list below (e.g.,{1,3,6,1, ...}) is the OID prefix minus the
* last sub-identifier.  The last sub-identifier is found in the
* object descriptor idbObjDesc_t structure.
*/

LOCAL idbOidTable_t oidTable[] = {
  /*   0: Scalar Object -- temperature */
  { IDB_SNMP_STRUCT, {1,3,6,1,4,1,123456,1,2}, 10,   /*lint !e785 */
    0, 1, { 0 },
    temperature_objDesc },

  /*   1: Scalar Object -- humidity */
  { IDB_SNMP_STRUCT, {1,3,6,1,4,1,123456,1,2}, 10,   /*lint !e785 */
    0, 1, { 0 },
    humidity_objDesc },

  /*   2: Scalar Object -- co2 */
  { IDB_SNMP_STRUCT, {1,3,6,1,4,1,123456,1,2}, 10,   /*lint !e785 */
    0, 1, { 0 },
    co2_objDesc },

  /*   3: Scalar Object -- airQuality */
  { IDB_SNMP_STRUCT, {1,3,6,1,4,1,123456,1,2}, 10,   /*lint !e785 */
    0, 1, { 0 },
    airQuality_objDesc },

  /*   4: Scalar Object -- brightness */
  { IDB_SNMP_STRUCT, {1,3,6,1,4,1,123456,1,2}, 10,   /*lint !e785 */
    0, 1, { 0 },
    brightness_objDesc },

  { IDB_TERMINATOR }
};

/*****************************************************************************
* IDB+ Module Translate Table
*/

LOCAL idbXlateTable_t xlateTable[] = {
    { &oidTable[  0], &temperature_objDesc[0] },
    { &oidTable[  1], &humidity_objDesc[0] },
    { &oidTable[  2], &co2_objDesc[0] },
    { &oidTable[  3], &airQuality_objDesc[0] },
    { &oidTable[  4], &brightness_objDesc[0] },

    { 0 }
};

/******************************************************************************
* User Local Functions.
*/

/* %%BeginUserCode weatherInHouseMib_UserFunctions */
/* %%EndUserCode   weatherInHouseMib_UserFunctions */


/****************************************************************************
*
* weatherInHouseMibInit - initialize/register weatherInHouseMib and objects.
*
* This routine initializes the modules IDB routines.
*
* RETURNS: SNMP_OK or SNMP_ERROR
*
* ERRNO: N/A
*/

STATUS weatherInHouseMibInit
    (
    void * parm1,
    void * parm2
    )
    {
    STATUS    rc;

    /* %%BeginUserCode weatherInHouseMibInit_Prolog */
    /* %%EndUserCode   weatherInHouseMibInit_Prolog */

    rc = SNMP_OK;

    /* %%BeginUserCode weatherInHouseMibInit_Body */
    /* %%EndUserCode weatherInHouseMibInit_Body */

    /* Register the module's information with IDB+ engine */
    rc = idbModuleRegister( moduleName, &xlateTable[0] );

    /* %%BeginUserCode weatherInHouseMibInit_Epilog */
    /* %%EndUserCode   weatherInHouseMibInit_Epilog */

    return( rc );
    }

/******************************************************************************
*
* weatherInHouseMibTerminate - Terminate weatherInHouseMib and objects.
*
* This routine de-initializes the IDB module functions.
*
* RETURNS: SNMP_OK or SNMP_ERROR
*
* ERRNO: N/A
*/

STATUS weatherInHouseMibTerminate
    (
    void * parm
    )
    {
    STATUS    rc;

    /* %%BeginUserCode weatherInHouseMibTerminate_Prolog */
    /* %%EndUserCode   weatherInHouseMibTerminate_Prolog */

    rc = SNMP_OK;

    /* De-register the module's information with IDB+ engine */
    idbModuleDeRegister( moduleName );

    /* %%BeginUserCode weatherInHouseMibTerminate_Epilog */
    /* %%EndUserCode   weatherInHouseMibTerminate_Epilog */

    return( rc );
    }

/******************************************************************************
*
* weatherInHouseMibScalarHandler - handles all scalar objects.
*
* This routine handles all scalar objects for this IDB+ Module.
*
* RETURNS: SNMP_OK or SNMP_ERROR
*
* ERRNO: N/A
*/

LOCAL STATUS weatherInHouseMibScalarHandler
    (
    idbRequest_t request,
    idb_t * idb
    )
    {
    STATUS    rc;

    /* %%BeginUserCode weatherInHouseMibScalarHandler_Prolog */
    /* %%EndUserCode   weatherInHouseMibScalarhandler_Prolog */

    rc = SNMP_OK;

    /* Validate the Scalar indexSubIdCount and instance value */
    if ( idbScalarValidate( request, idb ) == SNMP_ERROR )
        return idbErrorRequestMap( request );

    switch( idb->localId )
    {
    default:
        rc = idbErrorNoSuchInstance();
        break;

    /* ================================================================= */
    case temperature:    /* INTEGER, read-only */
        {
        /* %%BeginUserCode temperature_Body */

        switch ( request )
        {
        case IDB_GET_NEXT:
            /* Check to make sure the next object is valid. */
            rc = idbNextScalarIndex(idb);

            /* FALLTHRU */
        case IDB_GET:
			rc = jilian_demo_get (idb->pValueBuf);
            if ( rc == SNMP_OK )
            {
                idb->valueLen = 4;
            }

            break;

        case IDB_VALIDATE:
            break;

        case IDB_SET_NVM:
            break;

        case IDB_COMMIT:
            break;
        }

        /* %%EndUserCode   temperature_Body */
        }
        break;

    /* ================================================================= */
    case humidity:    /* Unsigned32, read-only */
        {
        /* %%BeginUserCode humidity_Body */

        switch ( request )
        {
        case IDB_GET_NEXT:
            /* Check to make sure the next object is valid. */
            rc = idbNextScalarIndex(idb);

            /* FALLTHRU */
        case IDB_GET:
			rc = jilian_demo_get (idb->pValueBuf);
            if ( rc == SNMP_OK )
            {
                idb->valueLen = 4;
            }

            break;

        case IDB_VALIDATE:
            break;

        case IDB_SET_NVM:
            break;

        case IDB_COMMIT:
            break;
        }

        /* %%EndUserCode   humidity_Body */
        }
        break;

    /* ================================================================= */
    case co2:    /* Unsigned32, read-only */
        {
        /* %%BeginUserCode co2_Body */

        switch ( request )
        {
        case IDB_GET_NEXT:
            /* Check to make sure the next object is valid. */
            rc = idbNextScalarIndex(idb);

            /* FALLTHRU */
        case IDB_GET:
			rc = jilian_demo_get (idb->pValueBuf);
            if ( rc == SNMP_OK )
            {
                idb->valueLen = 4;
            }

            break;

        case IDB_VALIDATE:
            break;

        case IDB_SET_NVM:
            break;

        case IDB_COMMIT:
            break;
        }

        /* %%EndUserCode   co2_Body */
        }
        break;

    /* ================================================================= */
    case airQuality:    /* Unsigned32, read-only */
        {
        /* %%BeginUserCode airQuality_Body */

        switch ( request )
        {
        case IDB_GET_NEXT:
            /* Check to make sure the next object is valid. */
            rc = idbNextScalarIndex(idb);

            /* FALLTHRU */
        case IDB_GET:
			rc = jilian_demo_get (idb->pValueBuf);
            if ( rc == SNMP_OK )
            {
                idb->valueLen = 4;
            }

            break;

        case IDB_VALIDATE:
            break;

        case IDB_SET_NVM:
            break;

        case IDB_COMMIT:
            break;
        }

        /* %%EndUserCode   airQuality_Body */
        }
        break;

    /* ================================================================= */
    case brightness:    /* Unsigned32, read-only */
        {
        /* %%BeginUserCode brightness_Body */

        switch ( request )
        {
        case IDB_GET_NEXT:
            /* Check to make sure the next object is valid. */
            rc = idbNextScalarIndex(idb);

            /* FALLTHRU */
        case IDB_GET:
			rc = jilian_demo_get (idb->pValueBuf);
            if ( rc == SNMP_OK )
            {
                idb->valueLen = 4;
            }

            break;

        case IDB_VALIDATE:
            break;

        case IDB_SET_NVM:
            break;

        case IDB_COMMIT:
            break;
        }

        /* %%EndUserCode   brightness_Body */
        }
        break;

    }

    /* %%BeginUserCode weatherInHouseMibScalar_Epilog */
    /* %%EndUserCode   weatherInHouseMibScalar_Epilog */

    return( rc );
    }